package com.taobao.livis;

import java.util.List;

import com.taobao.common.searchengine.SearchResult;
import com.taobao.item.domain.ItemDO;
import com.taobao.item.domain.result.ResultDO;
import com.taobao.item.exception.IcException;
import com.taobao.item.search.item.ItemSearchDO;
import com.taobao.item.search.item.ItemSearchQuery;
import com.taobao.item.search.iteminstant.ItemInstantSimpleQuery;
import com.taobao.item.service.ItemInstantSearchService;
import com.taobao.item.service.ItemSearchService;
import com.taobao.item.service.ItemTairCacheService;
import com.taobao.item.service.client.ItemQueryServiceClient;

public class QueryItemTest {

	private ItemQueryServiceClient itemQueryServiceClient;

	private ItemTairCacheService itemTairCacheService;

	private ItemSearchService itemSearchService;
	//这个对象一直为空，配置文件 在
	private ItemInstantSearchService itemInstantSearchService;

	public ItemDO getItemById(long itemId) throws IcException {
		ResultDO<ItemDO> res = itemQueryServiceClient
				.queryItemForDetail(itemId);
		return res.getModule();
	}

	public List<ItemSearchDO> searchItem(ItemSearchQuery isq) {
		try {
			List<ItemSearchDO> items = itemSearchService
					.search4ItemSearchDO(isq);
			return items;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public SearchResult searchItemByIss(ItemInstantSimpleQuery q){
		SearchResult sr = null;
		try {
			sr = itemInstantSearchService.searchItem2GoodsOnSale(q);
		} catch (IcException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return sr;
	}
	

	public void setItemQueryServiceClient(
			ItemQueryServiceClient itemQueryServiceClient) {
		this.itemQueryServiceClient = itemQueryServiceClient;
	}

	public ItemQueryServiceClient getClient() {
		return this.itemQueryServiceClient;
	}

	public ItemTairCacheService getItemTairCacheService() {
		return itemTairCacheService;
	}

	public void setItemTairCacheService(
			ItemTairCacheService itemTairCacheService) {
		this.itemTairCacheService = itemTairCacheService;
	}

	public void setItemSearchService(ItemSearchService itemSearchService) {
		this.itemSearchService = itemSearchService;
	}

	public ItemInstantSearchService getItemInstantSearchService() {
		return itemInstantSearchService;
	}

	public void setItemInstantSearchService(
			ItemInstantSearchService itemInstantSearchService) {
		this.itemInstantSearchService = itemInstantSearchService;
	}

}
